package lab.anoper.juc.automatic;

import java.util.concurrent.locks.ReentrantLock;

/**
 * @author 闫家洪（yanjiahong@vcredit.com）
 * @since 2024/12/12
 */
public class MyAtomicInteger {
    private int value;
    private final ReentrantLock lock = new ReentrantLock(true);

    public MyAtomicInteger(int value) {
        this.value = value;
    }

    public int incrementAndGet() {
        lock.lock();
        value = value + 1;
        lock.unlock();
        return value;
    }

    public int get() {
        lock.lock();
        try {
            return value;
        } finally {
            lock.unlock();
        }
    }

}
